package com.naiterui.ehp.bs.agent.controller;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.bo.agent.CustomOrderInfoBO;
import com.naiterui.ehp.bp.bo.statistics.CustomOrderReportBO;
import com.naiterui.ehp.bp.bo.statistics.CustomProductReportBO;
import com.naiterui.ehp.bp.bo.statistics.CustomRecipelConsultReportBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BaseExceptionCodes;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.agent.po.CustomPagePO;
import com.naiterui.ehp.bs.agent.service.ICustomService;
import com.naiterui.ehp.bs.agent.vo.AgentCustomItemVO;
import com.naiterui.ehp.bs.agent.vo.CustomAppDetailVO;
import com.naiterui.ehp.bs.agent.vo.CustomDetailVO;
import com.naiterui.ehp.bs.agent.vo.CustomOrderListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户管理
 * 
 * @author yangfuya
 * @since 2022/2/15
 */
@Slf4j
@Api(tags = {SwaggerTag.AGENT + "客户管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/custom")
public class CustomController {
    private final ICustomService customService;

    @ApiOperation("获取处方/问诊数据报表")
    @GetMapping("getRecipelAndConsult")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "customId", value = "客户id", dataType = "long", paramType = "query", required = true),
        @ApiImplicitParam(name = "reportType", value = "报告类型：1.年 2.月 3.日", dataType = "int", paramType = "query",
            required = true),
        @ApiImplicitParam(name = "reportDate", value = "年月日 yyyy-MM-dd格式", dataType = "string", paramType = "query")})
    private CustomRecipelConsultReportBO getRecipelAndConsult(Long customId, Integer reportType, String reportDate) {
        return customService.getRecipelAndConsult(customId, reportType, reportDate);
    }

    @ApiOperation("获取药品数据报表")
    @GetMapping("getProduct")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "customId", value = "客户id", dataType = "long", paramType = "query", required = true),
        @ApiImplicitParam(name = "reportType", value = "报告类型：1.年 2.月 3.日", dataType = "int", paramType = "query",
            required = true),
        @ApiImplicitParam(name = "reportDate", value = "年月日 yyyy-MM-dd格式", dataType = "string", paramType = "query")})
    private CustomProductReportBO getProduct(Long customId, Integer reportType, String reportDate) {
        return customService.getProduct(customId, reportType, reportDate);
    }

    @ApiOperation("获取订单数据报表")
    @GetMapping("getOrder")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "customId", value = "客户id", dataType = "long", paramType = "query", required = true),
        @ApiImplicitParam(name = "reportType", value = "报告类型：1.年 2.月 3.日", dataType = "int", paramType = "query",
            required = true),
        @ApiImplicitParam(name = "reportDate", value = "年月 yyyy-MM格式", dataType = "string", paramType = "query")})
    private CustomOrderReportBO getOrder(Long customId, Integer reportType, String reportDate) {
        return customService.getOrder(customId, reportType, reportDate);
    }

    @ApiOperation("获取昨日订单列表")
    @GetMapping("getOrderList")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "customId", value = "客户id", dataType = "long", paramType = "query", required = true),
        @ApiImplicitParam(name = "orderSn", value = "订单编号", dataType = "string", paramType = "query")})
    private PageVO<CustomOrderListVO> getOrderList(PageParamVO paramVO, Long customId, String orderSn)
        throws BusinessException {
        return customService.getOrderList(paramVO, customId, orderSn);
    }

    @ApiOperation("获取订单详情")
    @GetMapping("getOrderDetail")
    @ApiImplicitParam(name = "orderSn", value = "订单编号", dataType = "string", paramType = "query")
    private CustomOrderInfoBO getOrderList(@RequestParam String orderSn) throws BusinessException {
        return customService.getOrderDetail(orderSn);
    }

    @GetMapping("/list")
    @ApiOperation("查询客户列表")
    public PageVO<AgentCustomItemVO> get(PageParamVO pageParamVO, CustomPagePO customPagePO) throws BusinessException {
        if (customPagePO.getAgentId() == null) {
            throw new BusinessException(BaseExceptionCodes.PARAM_ERROR);
        }
        return customService.findCustomPage(pageParamVO, customPagePO);
    }

    @GetMapping("/get")
    @ApiOperation("查询客户详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "agentId", value = "经纪人Id", dataType = "long", paramType = "query", required = true),
            @ApiImplicitParam(name = "customId", value = "客户ID", dataType = "long", paramType = "query", required = true),
    })
    public CustomDetailVO get(@RequestParam Long agentId, @RequestParam Long customId) throws BusinessException {
        return customService.getDetail(agentId, customId);
    }

    @PostMapping("/starLev/save")
    @ApiOperation("修改客户星级")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "agentId", value = "经纪人ID", dataType = "long", paramType = "query", required = true),
            @ApiImplicitParam(name = "customId", value = "客户ID", dataType = "long", paramType = "query", required = true),
            @ApiImplicitParam(name = "starLev", value = "星级", dataType = "int", paramType = "query", required = true),
    })
    public void saveStarLev(@RequestHeader Long agentId, Long customId, Integer starLev) throws BusinessException {
        customService.updateStarLev(agentId, customId, starLev);
    }

    @GetMapping("/app/info")
    @ApiOperation("客户APP详情")
    public CustomAppDetailVO getAppDetail() throws BusinessException {

        return customService.getCustomAppDetail();
    }

}
